<template>
    <div>
        <el-drawer title="供应商列表" v-model="drawerVisible" :before-close="handleClosed">
            <el-row>
                <el-col :span="22">
                    <el-input v-model="queryParam.name" placeholder="请输入供应商名称"></el-input>
                </el-col>
                <el-col :span="2">
                    <el-button type="primary">
                        <bar-icon :icon="'select'" :width="15" :height="15" :color="'#ffffff'"/>
                    </el-button>
                </el-col>
            </el-row>
            <el-table :data="supporters" stripe style="width: 100%">

                <el-table-column prop="nameZh" label="名称"></el-table-column>
                <el-table-column label="等级">
                    <template #default="scope">
                        <el-tag :type="scope.row.level === 1 ? 'primary' : 'info'">
                            {{ scope.row.level === 1 ? '重点供应商' : '普通供应商' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column prop="score" label="评分"></el-table-column>
                <el-table-column prop="status" label="状态">
                    <template v-slot="{ row }">
                        <el-tag :type="row.status === 1 ? 'success' : 'danger'">
                            {{ row.status === 1 ? '启用' : '禁用' }}
                        </el-tag>
                    </template>
                </el-table-column>
                <el-table-column label="操作">
                    <template #default="scope">
                        <el-button @click="handleAdd(scope.row)">绑定</el-button>
                    </template>
                </el-table-column>
            </el-table>
        </el-drawer>
    </div>
</template>

<script>
import SupporterDialog from "@/components/widget/dialog/SupporterDialog.vue";
import BarIcon from "@/components/widget/icon/BarIcon.vue";
import supporterAPI from "@/util/request-md/supporter/supporter.js";


export default {
    components: {BarIcon, SupporterDialog},
    emits: ['callClosed', 'callDataSelected'],
    props: ['visible'],
    watch: {
        visible(val) {
            this.drawerVisible = val
        }
    },
    data() {
        return {
            drawerVisible: false,
            queryParam: {
                name: '',
            },
            supportData: {},
            makeProDialogVisible: false,
            supporters: []
        }
    },

    methods: {
        handleClosed() {
            console.log("执行了关闭");
            this.$emit('callClosed')
        },
        loadSupporters() {
            supporterAPI.getAllSupporters((res) => {
                if (res.code === 200) {
                    this.supporters = res.data;
                }
            });
        },
        handleAdd(data) {
            this.supportData = data;
            this.$emit('callDataSelected', data);
        },
        handleMakePorClosed() {

        }

    },
    mounted() {
        this.loadSupporters();
    }
}
</script>

<style scoped>

</style>